package com.example.rabbitmq.demo.controller;

import com.example.rabbitmq.demo.entity.OrderEntity;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/test")
public class TestController {
    @Autowired
    RabbitTemplate rabbitTemplate;

    @RequestMapping("/sendOrder")
    public String sendOrder(@RequestParam("name") String name){
        OrderEntity orderEntity = new OrderEntity();
        orderEntity.setId(1L);
        orderEntity.setMemberUsername(name);
        rabbitTemplate.convertAndSend("order-event-exchange","order.release.queue",orderEntity);
        return "OK";
    }
}
